package com.informet.ipd.modelo.dao;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import com.informet.ipd.modelo.vo.CrecerConDeporteVO;
import com.informet.ipd.modelo.vo.TalentoVO;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author LAPTOP01
 */
public class TalentoEvalFisicaDao extends DBase{


  Connection conn = null;

    public TalentoEvalFisicaDao() {
        super();
    }


    public void  setListAspectoTecnioCombo(TalentoVO bean, ResultSet rs) throws SQLException{
          bean.setCodAspTecnico(rs.getString("NUM_CODASPfis_pf"));
          bean.setDescAspTecnico(rs.getString("TX_DESCASPfis"));
    }

    public void  setListAspectoTecnioPuntoEntrada(TalentoVO bean, ResultSet rs) throws SQLException{

          bean.setCodAspTecnico(rs.getString("NUM_CODASPfis_pf"));
          bean.setCodAlumCcd(rs.getString("NUM_codalumtal_pk"));
          bean.setCodCcd(Integer.parseInt(rs.getString("num_talento_pk")));
          bean.setNumEntradaEt(rs.getString("num_entradaef"));


          bean.setDescAspTecnico(rs.getString("TX_DESCASPfis"));
          bean.setNumPuntuacionPersonal(rs.getString("NUM_RESULTADOPERSONAL"))   ;

          
    }
// lista aspectos fisicos no depende de disciplinas segun erwin
    public List getListAspectosTecnicosPorDisciplina(String codDisc,String codAlumno) throws SQLException {

        Statement stmt = null;
        ResultSet rs = null;
        ArrayList<TalentoVO> lista = new ArrayList<TalentoVO>(0);
        String sql = "";
        
        try {
            conn = DriverManager.getConnection(url, usuario, password);            
            stmt = conn.createStatement();
                        sql = " select "+
                              "          * "+
                              " from me_aspfisicostal "+
                              " where num_codaspfis_pf not in(select "+
                              "                                    num_codaspfis_pf "+
                              "                               from me_evafistal "+
                              "                               where num_codalumtal_pk="+codAlumno+
                              "                               )"
                             ;


            rs = stmt.executeQuery(sql);
            TalentoVO bean1 = null;
            while (rs.next()) {
                bean1 = new TalentoVO();
                setListAspectoTecnioCombo(bean1, rs);
                lista.add(bean1);
            }
           
        } finally {
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
                stmt.close();
                stmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }

        }
      // JOptionPane.showMessageDialog(null, lista.size());
        return lista;
    }
       

    public List getListAspectosTecnicosPunatajeEntrada(String codDisc,String codAlumno) throws SQLException {

        Statement stmt = null;
        ResultSet rs = null;
        ArrayList<TalentoVO> lista = new ArrayList<TalentoVO>(0);
        String sql = "";

        try {
            conn = DriverManager.getConnection(url, usuario, password);
            stmt = conn.createStatement();
                        sql = " select "+
                              "  isnull(num_entradaef,0) as num_entradaet, "+
                              "          * "+
                              " from me_evafistal e inner join me_aspfisicostal a on a.num_codaspfis_pf=e.num_codaspfis_pf"+
                              " where 1=1"+
                              "      and e.num_codalumtal_pk="+codAlumno;


            rs = stmt.executeQuery(sql);
            TalentoVO bean1 = null;
            while (rs.next()) {
                bean1 = new TalentoVO();
                setListAspectoTecnioPuntoEntrada(bean1, rs);
                lista.add(bean1);
            }

        } finally {
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
                stmt.close();
                stmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }

        }
      // JOptionPane.showMessageDialog(null, lista.size());
        return lista;
    }

      public String spMan(TalentoVO bean, String putuacionPersonal) {
        String msj = "";
        //String codP=bean.getCodPrograma();
        try {
        	
            conn = DriverManager.getConnection(url, usuario, password);
            CallableStatement cs = conn.prepareCall("{call Man_update_TalentoAlumnoEvaFisica(?,?,?,?,?,?)}");
            //codActividad, codAnio, titu_programa,justificacion,fechaInicio, fechaFin,monto
            cs.setString(1, bean.getCodAspTecnico());
            cs.setString(2, bean.getNumEntradaEt());
            cs.setInt(3, bean.getCodCcd());
            cs.setString(4, bean.getCodAlumno());
            cs.setString(5, bean.getTipoOper());
            cs.setString(6, putuacionPersonal);
            cs.execute();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.toString());
            msj = e.toString();
            return msj;
        }
        return msj;
    }

}
